import {execute} from "../db/mysql";
import {sendPostHttpRequest, sleep} from "../utils/utils";

export const hongshuexec =()=>{
    execute("select * from ori_data where is_do=0 limit 4","",(result)=>{
        for (const item of result) {
            sleep(500);
            const url = "https://www.xiaohongshu.com/explore/"+item.note_id;
            console.log(url)
            fetchurl(url).then(async (res)=>{
                const data =   {
                    str:res,
                    id: item.id
                };
                await sendPostHttpRequest(data);
            });
            //sleep(3000);
        }
    })
}

const fetchhomeUrl =(url:string)=>{
    return fetch(url, {
        "headers": {
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "accept-language": "zh-CN,zh;q=0.9",
            "cache-control": "no-cache",
            "pragma": "no-cache",
            "sec-ch-ua": "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"Windows\"",
            "sec-fetch-dest": "document",
            "sec-fetch-mode": "navigate",
            "sec-fetch-site": "same-origin",
            "sec-fetch-user": "?1",
            "upgrade-insecure-requests": "1",
            "cookie": "abRequestId=061d97d4-ba33-5e49-be34-a226e6b3b353; xsecappid=xhs-pc-web; a1=18b1d7f1130o70uf5lg7qut4j1yym3jhzamlyggh850000306892; webId=33b24ed0c77916470ab0089b2abf7a79; gid=yYDyfWi42KuyyYDyfWiyy0kkq8lW87i21kWA6xY794Vyv128v6qVxv888q8KYjJ8804y42K2; web_session=040069b069bc0956403ef70d13374bfe5723d2; webBuild=3.10.6; cache_feeds=[]; websectiga=8886be45f388a1ee7bf611a69f3e174cae48f1ea02c0f8ec3256031b8be9c7ee; sec_poison_id=26a88081-ff4c-4c85-9cfe-6508613d6d14; unread={%22ub%22:%226524c62e000000001c01413e%22%2C%22ue%22:%2265014a79000000001e00cf64%22%2C%22uc%22:33}",
            "Referer": "https://www.xiaohongshu.com/search_result?keyword=CHLOE&source=web_explore_feed",
            "Referrer-Policy": "strict-origin-when-cross-origin"
        },
        "body": null,
        "method": "GET"
    }).then(res=>res.text());
}

const fetchurl = (url:string)=>{
    return  fetch(url, {
        "headers": {
            "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
            "accept-language": "zh-CN,zh;q=0.9",
            "cache-control": "no-cache",
            "pragma": "no-cache",
            "sec-ch-ua": "\"Google Chrome\";v=\"117\", \"Not;A=Brand\";v=\"8\", \"Chromium\";v=\"117\"",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"Windows\"",
            "sec-fetch-dest": "document",
            "sec-fetch-mode": "navigate",
            "sec-fetch-site": "same-origin",
            "sec-fetch-user": "?1",
            "upgrade-insecure-requests": "1",
            "cookie": "abRequestId=061d97d4-ba33-5e49-be34-a226e6b3b353; xsecappid=xhs-pc-web; a1=18b1d7f1130o70uf5lg7qut4j1yym3jhzamlyggh850000306892; webId=33b24ed0c77916470ab0089b2abf7a79; gid=yYDyfWi42KuyyYDyfWiyy0kkq8lW87i21kWA6xY794Vyv128v6qVxv888q8KYjJ8804y42K2; web_session=040069b069bc0956403ef70d13374bfe5723d2; webBuild=3.10.6; cache_feeds=[]; unread={%22ub%22:%226526ba74000000001a022c8d%22%2C%22ue%22:%22651e7e0e000000001e00e56b%22%2C%22uc%22:18}; websectiga=6169c1e84f393779a5f7de7303038f3b47a78e47be716e7bec57ccce17d45f99; sec_poison_id=8c1cb3e9-3de5-4521-9f84-e3ff8901dad0"
        },
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": null,
        "method": "GET"
    }).then(response=>response.text()) ;
}